package com.hongye.third.processor;

import com.hongye.third.feign.HongyeHouseFeign;
import com.hongye.third.vo.HongyeHouse;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @progam:medical-care
 * @author:GJS
 * @Time:2022/4/12 16:36
 */
@RequestMapping("processor")
@RestController
public class SettledGuestProcessor {

    @Autowired
    private HongyeHouseFeign hongyeHouseFeign;

    /**
     *
     * @param url 网页地址
     */
    @RequestMapping("jsoupList")
    public  void jsoupList(String url){
        try {
            //传入地址，通过get方式访问
            Document document = Jsoup.connect(url).get();

            for (int i = 1; i <= 60; i++) {

                Elements elements = document.select("#container > div.list-contents.theme-ajk-listcont > div.list-results > div.key-list.imglazyload > div:nth-child("+i+") > div > a.lp-name > span");
                Elements elements2 = document.select("#container > div.list-contents.theme-ajk-listcont > div.list-results > div.key-list.imglazyload > div:nth-child("+i+") > div > a.address > span");
                Elements elements3 = document.select("#container > div.list-contents.theme-ajk-listcont > div.list-results > div.key-list.imglazyload > div:nth-child("+i+") > a.favor-pos > p > span");

                for (Element element : elements) {
//                    System.out.println(element);
                    //获取
                    String title = element.ownText();
//                    System.out.println(title);
                }
                for (Element element : elements2) {
//                    System.out.println(element);
                    //获取
                    String title = element.ownText();
//                    System.out.println(title);
                }
                for (Element element : elements3) {
                    //获取
                    String title = element.ownText();

                }

            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {

       try {
           for (int i = 1; i <= 1; i++) {
               String url = "https://sh.fang.anjuke.com/loupan/all/p"+i;
               SettledGuestProcessor processor = new SettledGuestProcessor();
               processor.jsoupList(url);
           }
       }catch (Exception e){
           System.out.println("异常阻止："+e);
       }

    }
}
